<!--
 * @Description:
 * @Author bianpengfei
 * @create 2022/11/8 23:09
 -->
<template>
  <div class="page !h-[calc(100vh-150px)]">
    <div class="bg-[#fff] max-w-850px px-12px py-10px">
      <g-title> 培训资料新增 </g-title>

      <el-form :model="form" label-width="100px" class="max-w-800px py-12px">
        <el-form-item
          prop="title"
          label="公告标题"
          :rules="[{ required: true, message: '请输入公告标题', trigger: 'blur' }]"
        >
          <el-input v-model="form.title" placeholder="请输入公告标题" clearable></el-input>
        </el-form-item>

        <el-form-item prop="des" label="内容" :rules="[{ required: true, message: '请输入', trigger: 'blur' }]">
          <el-input
            v-model="form.des"
            type="textarea"
            placeholder="请输入"
            clearable
            :autosize="{ minRows: 2, maxRows: 6 }"
          ></el-input>
        </el-form-item>

        <el-form-item prop="des" label="附件" :rules="[{ required: true, message: '请选择附件', trigger: 'blur' }]">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="3"
            :on-exceed="handleExceed"
            :file-list="form.files"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
          </el-upload>
        </el-form-item>

        <div class="flex justify-center items-center">
          <el-button type="primary">保存</el-button>
          <el-button @click="onReset">重置</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Index',
  data() {
    return {
      form: {
        title: '',
        des: '',
        files: []
      }
    }
  },

  computed: {},

  watch: {},

  created() {},

  mounted() {
    this.$once('hook:beforeDestroy', () => {
      // this.removeEvents()
    })
  },

  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
      )
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },

    onReset() {
      this.form = {
        ...this.form,
        title: '',
        des: '',
        files: []
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
}
</style>
